package com.jushu.storbox.view.mdmview;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.WindowManager;
import android.widget.ImageView;

import com.jushu.storbox.ShareDriveApplication;
import com.jushu.storbox.util.LogUtil;
import com.jushu.storbox.util.image.BitmapUtil;

public class PhotoDao extends ImageView implements IPictureDao, IBaseDao {

	private static final String TAG = "PhotoDao";
	private Activity mActivity;
	private Context context;
	private int window_width;
	private int window_height;
	private Bitmap bitmap;

	public PhotoDao(Context context, String filePath) {
		super(context);
		this.context = context;
		mActivity = (Activity)context;
		init();
//		initData();
		setBitmapImage(filePath);
		initAttach();
	}
	
	private void initAttach() {
		
	}

	public PhotoDao(Context context, String filePath, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		mActivity = (Activity)context;
		init();
//		initData();
		setBitmapImage(filePath);
		initAttach();
	}

	private void init() {
		WindowManager manager = mActivity.getWindowManager();
		window_width = manager.getDefaultDisplay().getWidth();
		window_height = manager.getDefaultDisplay().getHeight();
	}

	@Override
	public void setBitmapImage(String path) {
		// TODO Auto-generated method stub
//		bitmap = BitmapUtil.decodeSampledBitmapFromFile(path, window_width, window_height);
		bitmap = BitmapUtil.createImageThumbnail(path, window_width, window_height);
		if (null != bitmap) {
			ShareDriveApplication.getInstance().addTempBitmaps(bitmap);
			setImageBitmap(bitmap);
		} else {
			LogUtil.i(TAG, "bitmap is null");
		}
	}

	@Override
	public void onDestory() {
		recycleBitmap();
		
	}

	@Override
	public void onStop() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void recycleBitmap() {
		// TODO Auto-generated method stub
//		LogUtil.i(TAG, "start recycleBitmap...");
		BitmapUtil.recycleBitmap(bitmap);
	}
	

}
